﻿
#region Usings



using Microsoft.Xna.Framework;

#endregion

namespace PolyGameEngine.Tools
{
    public static class MyMathClass
    {
        public static Vector2 CalculateForceAtAngle(float Force, float Rotation)
        {
            float convertedAngle = MathHelper.ToDegrees(Rotation); // convert the angle to degrees for ease of use

            while (convertedAngle > 360) //Ensure the
                convertedAngle -= 360;   //Value is
            while (convertedAngle < 0)   //between
                convertedAngle += 360;   //0 and 360 degrees

            int quad = convertedAngle <= 90 ? 1 : convertedAngle <= 180 ? 2 : convertedAngle <= 270 ? 3 : 4;  //Quadrant for assigning polarity to X and Y vars later



            while (convertedAngle > 90)// adjust angle so that we can work in quadrant 1 on a normal cartesian axis
                convertedAngle -= 90;



            float Xvalue = convertedAngle / 90; //convert percentage to modify X and Y forces respectively
            float Yvalue = 1 - Xvalue;

            Xvalue *= Force; //Multiply percentage by linear force to adjust force in the direction
            Yvalue *= Force;

            if (quad == 1)
                return new Vector2(Xvalue, -Yvalue);
            if (quad == 2)
                return new Vector2(Yvalue, Xvalue);
            if (quad == 3)
                return new Vector2(-Xvalue, Yvalue);
            if (quad == 4)
                return new Vector2(-Yvalue, -Xvalue);


            return Vector2.Zero;
        }
    }
}
